package com.itee.javafx.property;

import com.itee.core.util.CalendarUtils;
import javafx.beans.NamedArg;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.TableColumn;
import javafx.scene.control.cell.PropertyValueFactory;

import java.util.Date;

/**
 * Created by gonglei on 2015/7/14.
 */
public class DatePropertyValueFactory<S,T> extends PropertyValueFactory   {

    /**
     * Creates a default PropertyValueFactory to extract the value from a given
     * TableView row item reflectively, using the given property name.
     *
     * @param property The name of the property with which to attempt to
     *                 reflectively extract a corresponding value for in a given object.
     */
    public DatePropertyValueFactory(@NamedArg("property")String property) {
        super(property);
    }

    @Override
    public ObservableValue call(TableColumn.CellDataFeatures param) {
        ReadOnlyObjectWrapper value = (ReadOnlyObjectWrapper) super.call(param);
        Date date= (Date) value.getValue();
        String dateStr= CalendarUtils.formatDate(date);
        value.setValue(dateStr);
        return value;
    }
}
